package com.example.demo_01.service.impl;

import com.example.demo_01.mapper.EmpMapper;
import com.example.demo_01.service.EmpService;
import com.example.demo_01.util.ResultBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    @Override
    public ResultBean findByParam(Map<String, String> param) {
        int pageNum = Integer.parseInt(param.get("pageNum"));
        int pageSize = Integer.parseInt(param.get("pageSize"));
        PageHelper.startPage(pageNum , pageSize);
        List<Map> list=empMapper.findByParam(param);
        if(list!=null&&list.size()>0){
            PageInfo<Map> personPageInfo = new PageInfo<Map>(list);
            return ResultBean.getInstance().success().setData(personPageInfo);
        }
        return ResultBean.getInstance().fail("查无数据");
    }

    @Override
    public ResultBean doSave(Map<String, String> param) {
        int row=empMapper.save(param);
        if(row>0){
            return ResultBean.getInstance().success("注册成功");
        }
        return ResultBean.getInstance().fail("注册失败");
    }

    @Override
    public ResultBean doUpdate(Map<String, String> param) {
        int row=empMapper.update(param);
        if(row>0){
            return ResultBean.getInstance().success("修改成功");
        }
        return ResultBean.getInstance().fail("修改失败");
    }

    @Override
    public ResultBean delete(String ids) {
        System.out.println("========="+ids);
        int row=empMapper.delete(ids);
        if(row>0){
            return ResultBean.getInstance().success("删除成功");
        }
        return ResultBean.getInstance().fail("删除失败");
    }
}
